<?php
$courtNameStr = Yii::t('BWeSport','Court Name');
$courtDescriptionStr = Yii::t('BWeSport','Court Description'); 
$courtAddressStr = Yii::t('BWeSport','Court Address');
$modifyStr = Yii::t('BWeSport','Modify');
$addCourtStr = Yii::t('BWeSport','Add Court');
$deleteStr = Yii::t('BWeSport','Delete');
$app = Blyn::app()->getActiveApp();
$event = new BWEvent($eventId);
$vender = $event->getMessageManager()->getMessage('vender');
$bookableMessage = new BWMessage($bookableId);
$courtInputMedia = $bookableMessage->getInputMediaManager()->getInputMedia('court');
$courtConfigList = array();
if ($courtInputMedia instanceof BWInputMedia) {
    $courtConfigList = $courtInputMedia->getMessageManager()->getMessageList();
    $inputType = $courtInputMedia->getInputType();
    $countOfCourt = count($courtConfigList);
} else {
    $courtInputMedia = new BWInputMedia($bookableMessage);
    $courtInputMedia->name = 'court';
    $courtInputMedia->save();
    $courtInputMedia->setInputType(new BWKeyValueType());
    $bookableMessage->getInputMediaManager()->addInputMedia($courtInputMedia);
}
?>
<link rel="stylesheet" type="text/css"
      href="<?php echo Yii::app()->request->baseUrl; ?>/css/bootstrap-datetimepicker.min.css" />
<script  type="text/javascript"
         src="<?php echo Yii::app()->request->baseUrl; ?>/js/bootstrap-datetimepicker.min.js"/>

<script type="text/javascript">
    $(document).ready(function() {
        $("#selectAll").click(function() {
            if ($(this).attr("checked") == "checked") {
                $(":checkbox").attr("checked", true);
            } else {
                $(":checkbox").attr("checked", false);
            }
        });
        
        $("#myModal").modal("hide");

    });
</script> 
<script type="text/javascript">
    $(function() {
        $('.tree li:has(ul)').addClass('parent_li').find(' > span').attr('title', 'Collapse this branch');
        $('.tree li.parent_li > span').on('click', function(e) {
            var children = $(this).parent('li.parent_li').find(' > ul > li');
            if (children.is(":visible")) {
                children.hide('fast');
                $(this).attr('title', 'Expand this branch').find(' > i').addClass('icon-plus-sign').removeClass('icon-minus-sign');
            } else {
                children.show('fast');
                $(this).attr('title', 'Collapse this branch').find(' > i').addClass('icon-minus-sign').removeClass('icon-plus-sign');
            }
            e.stopPropagation();
        });
    });</script>
<script type="text/javascript">
    $(function() {
        $("#Event_Shop_CX").click(function() {
            document.getElementById("Event_Shop_CX_View").style.display = '';
            document.getElementById("Event_Clothes_CX_View").style.display = 'none';
        });
        $("#Event_Clothes_CX").click(function() {
            document.getElementById("Event_Shop_CX_View").style.display = 'none';
            document.getElementById("Event_Clothes_CX_View").style.display = '';
        });
    });
</script>

<fieldset>
    <table class="table table-hover">
        <thead>
            <tr>
                <th>
                    <input type="checkbox"  id="selectAll"> 
                </th>
                <th><?php echo $courtNameStr; ?></th>
                <th><?php echo $courtDescriptionStr; ?></th>
                <th><?php echo $courtAddressStr; ?></th>               
            </tr> 
        </thead>
        <tbody>
            <?php foreach ($courtConfigList as $theId => $courtConfig) { ?>
                <tr>
                    <td><label class="checkbox">
                            <input type="checkbox" name="checkbox[]" value="<?php echo $theId; ?>"> 
                        </label></td>
                    <td> <?php echo $courtConfig->getMediaManager()->getMedia('displayName')->getContent(); ; ?> </td>
                    <td> <?php echo $courtConfig->getMediaManager()->getMedia('description')->getContent(); ?> </td>
                    <td> <?php echo $courtConfig->getMediaManager()->getMedia('address')->getContent(); ?> </td>
                    <td>
                        <div class="row-fluid">                         
                            <?php
                            $theCourtId = $courtConfig->getId();
                            echo $control->getAjaxLink(array('name' => $modifyStr, 'id' => 'showAddCourt'), array(
                                'courtId' => $theCourtId,
                                'eventId' => $eventId,
                                'bookableId' => $bookableId,
                                'ajaxContainerId' => 'myModal',
                                'htmlOptions' => array(
                                    'enctype' => 'multipart/form-data'),
                                'ajaxOptions' => array(
                                    'complete' => 'function(){$("#ajax-loaderdiv").hide();$("#myModal").modal("show");}')
                            ));
                            ?>  
                            <?php echo ' | '; ?>
                            <?php
                            echo $control->getAjaxLink(array('name' => '删除', 'id' => 'deleteCourt'), array(
                                'courtId' => $theCourtId,
                                'eventId' => $eventId,
                                'bookableId' => $bookableId,
                                'htmlOptions' => array(
                                    'enctype' => 'multipart/form-data')
                            ));
                            ?>  
                        </div>                      
                    </td>
                </tr>
            <?php } ?>
        </tbody>
    </table>

    <div class="row-fluid">
        <?php
        echo $control->getAjaxLink(array('name' => $addCourtStr, 'id' => 'showAddCourt'), array(
            'eventId' => $eventId,
            'bookableId' => $bookableId,
            'theCourtId' => 0,
            'ajaxContainerId' => 'myModal',
            'htmlOptions' => array(
                'enctype' => 'multipart/form-data',
                'class' => 'btn'),
            'ajaxOptions' => array(
                'complete' => 'function(){$("#ajax-loaderdiv").hide();$("#myModal").modal("show");}',
                'error' => 'function() {alert("There may a error on uploading. Try again later");}'
            ),
        ));
        ?>
        <?php
        echo $control->getAjaxLink(array('name' =>$deleteStr, 'id' => 'deleteCheckedCourt'), array(
            'htmlOptions' => array(
                'class' => 'btn',
                'enctype' => 'multipart/form-data'),            
            'eventId' => $eventId,
            'bookableId' => $bookableId));
        ?>
    </div>   
    <div id="myModal" class="modal hide fade" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
    </div>

    <div><input type="hidden" name="curPageNo" value="1"></div>

    <div class="pagination">  
        <ul>  
            <li class="active">
                <a href="javascript:void()">前一页</a>    </li>  
            <li class="active">
                <a href="javascript:void()">1</a>    </li>  
            <li class="active">
                <a href="javascript:void()">后一页</a>    </li>  
        </ul>  
    </div>


